﻿#pragma once

#include "../DeviceLayer/DeviceDemoVoltage.h"
#include "Containers.h"
#include "Service.h"

namespace BusinessLayer
{


class ServiceDemoVoltage : public Service
{
    DECLARE_DYNAMIC_CREATE(ServiceDemoVoltage)

private:
    AUTO_WIRED_DEVICE(DeviceLayer::DeviceDemoVoltage, voltage)

public:
    ServiceDemoVoltage();

    void Switch(bool on)
    {
        voltage->PowerSwitch(on);
    }

    bool IsOn()
    {
        return voltage->IsOn();
    }

    void IncreaseVoltage()
    {
        voltage->SetVoltage(voltage->GetVoltage() + 0.1f);
        if (voltage->GetWarning())
            emit Error(1, "电压不正常");
        else
            emit Error(0, "");
    }

    void DecreaseVoltage()
    {
        voltage->SetVoltage(voltage->GetVoltage() - 0.1f);
        if (voltage->GetWarning())
            emit Error(2, "电压不正常");
        else
            emit Error(0, "");
    }

    float GetVoltage()
    {
        return voltage->GetVoltage();
    }

    bool GetWarning()
    {

        return voltage->GetWarning();
    }
};

}
